<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>日志内容</title>
		<link type="text/css" rel="stylesheet" href="../jquery-easyui-1.4.2/themes/default/easyui.css">
		<link type="text/css" rel="stylesheet" href="../jquery-easyui-1.4.2/themes/icon.css">
		<script type="text/javascript" src="../js/jquery-2.1.1.min.js"></script>
		<script type="text/javascript" src="../jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="../js/dateFormat_CY.js"></script>
		<link rel="stylesheet" href="../ueditor/themes/default/_css/umeditor.css" />
		<script type="text/javascript" src="../ueditor/umeditor.config.js" ></script>
		<script type="text/javascript" src="../ueditor/umeditor.min.js" ></script>
		<script type="text/javascript" src="../ueditor/lang/zh-cn/zh-cn.js" ></script>
		<script type="text/javascript">
			var pageNo = null,pageSize = null,total = null,logId =parseInt("${log.logId}"),pageCount = null;
		    $(function(){
		    	$.post('../log/loadComments.do?logId='+logId+'',{pageNo:1,pageSize:3},function(data){
					pageNo = data.pageNo;
					pageSize = data.pageSize;
					pageCount = data.pageCount;
					total = data.total;
					logId = eval(data.rows)[0].co_logId;
					param(data);
				},"JSON");
			
			}); 
			
			//提交评论
			function co_comment(){
				var comment = UM.getEditor('editor').body.innerHTML;
				$.post('../log/commitComment.do?logId='+logId+'',{comment:comment},function(data){
					if(data.msg=="ok"){
						alert("评论成功");
						UM.getEditor('editor').body.innerHTML="";
					}
				},"JSON");
			}
			//首页
			function firstPage(){
				if(pageNo==1){
					alert("已经是第一页了");
				}else{
					pageNo = 1;
					//同步请求
					//location.href="../log/seeLog.do?logId="+logId+"&pageNo="+pageNo+"&pageSize="+pageSize;
					//异步请求
					$.post('../log/loadComments.do?logId='+logId+'',{pageNo:pageNo,pageSize:pageSize},function(data){
						param(data);
					},"JSON");
				}
			}
			
			//上一页
			function previousPage(){
				if(pageNo==1){
					alert("已经是第一页了");
				}else{
					pageNo = pageNo-1;
					$.post('../log/loadComments.do?logId='+logId+'',{pageNo:pageNo,pageSize:pageSize},function(data){
						param(data);
					},"JSON");
				}
			}
			//下一页
			function nextPage(){
				if(pageNo==pageCount){
					alert("已经是最后一页了");
				}else{
					pageNo = pageNo+1;
					$.post('../log/loadComments.do?logId='+logId+'',{pageNo:pageNo,pageSize:pageSize},function(data){
						param(data);
					},"JSON");
				}
			};
			//尾页
			function lastPage(){
				if(pageNo==pageCount){
					alert("已经是最后一页了");
				}else{
					pageNo = pageCount;
					$.post('../log/loadComments.do?logId='+logId+'',{pageNo:pageNo,pageSize:pageSize},function(data){
						param(data);
					},"JSON");
				}
			};
			
			function param(data){
				var json = eval(data.rows);
				var con = null;
				$.each(json,function(index,item){
					var userName = json[index].userName;
					var comment = json[index].comment;
					var date = json[index].co_Date;
					if(con ==null){
						con =" <span>"+
							"<a href='javascript:firstPage();'>首页</a> "+
				  	        "<a href='javascript:previousPage();'>上一页</a> "+
				  	        "<a href='javascript:nextPage();'>下一页</a> "+
				  	        "<a href='javascript:lastPage();'>尾页</a> | "+
			  	        "</span>"+
			  	        "<span>共 <b>"+total+"</b> 条记录 每页显示 <b>"+pageSize+"</b> 条记录 | </span>"+
			  	        "<span>共 <b>"+pageCount+"</b> 页 当前是第 <b>"+pageNo+"</b> 页</span>";
					}
					con+="<div style='margin-top:10px'>"+
					"<b>"+userName+"</b>"+
					"<a>"+comment+"</a>"+
					
					"<div style='text-align:right;'>"+getLocalTime(date)+"</div>"+
					"<pre></pre>"+
					"<hr/>"+
					"</div>";
				});
				console.log(con);
				$("#co").html(con);
			};
			  function getLocalTime(jsondate) { 
				  jsondate=""+jsondate+"";//因为jsonDate是number型的indexOf会报错
				  if (jsondate.indexOf("+") > 0) {
	                  jsondate = jsondate.substring(0, jsondate.indexOf("+"));
	              }
	              else if (jsondate.indexOf("-") > 0) {
	                  jsondate = jsondate.substring(0, jsondate.indexOf("-"));
	              }
	              var date = new Date(parseInt(jsondate, 10));
	              var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
	              var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
	              var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
	              var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
	              var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
	              return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
			 } 
		</script>
	</head>
	<body>
		<a id="btn" href="javascript:history.go(-1)" class="easyui-linkbutton" style="margin-left: 10px;margin-top: 10px;" data-options="iconCls:'icon-back'">返回</a> 
		<div id="title" style="text-align: center;margin-top: 30px;color: #31B0D5;">
			${log.logTitle}
		</div>
		<div id="logDate" style="text-align: center;margin-top: 30px;">
			发布时间：${log.logDateTime }
			<div id="userName">作者：${log.userName }</div>
		</div>
		<div id="context" style="width: 90%; text-indent: 100px;margin-top: 50px;">
			${log.logContext }
		</div>
		<div id="logType" style="width: 90%; margin-left: 10px;color:#31B0D5;margin-top: 30px;">
			类别：${log.typeName }
		</div>
		<div id="logType" style="width: 90%; margin-left: 10px;color:#31B0D5;">
			附件：
		</div>

		<div class="jump-page">
	    </div>
		<div id = "co">
		</div>	
		<div>
			<textarea id="editor" style="width: 98%;height:100px;"></textarea>
			<script type="text/javascript">
				//渲染编辑器
	    		var ue = UM.getEditor('editor');
	    		function callback(imgUrl){
	    			alert(imgUrl);
	    		}
			</script>
		</div>
		
		<a id="btn" href="javascript:co_comment();" class="easyui-linkbutton" style="margin-left:50%;margin-top: 10px;" data-options="iconCls:'icon-ok'">提交</a> 
		
	</body>
</html>